package leetcode.string;

/**
 * @author Cheng Jun
 * Description: https://leetcode.cn/problems/compare-version-numbers/
 * @version 1.0
 * @date 2022/7/22 20:34
 */
public class compareVersion {
    public static void main(String[] args) {

    }

    // 思路：split，然后比较每个位置的数字
    static int compareVersion(String version1, String version2) {
        String[] v1 = version1.split("\\.");
        String[] v2 = version2.split("\\.");
        int maxLen = Math.max(v1.length, v2.length);
        for (int i = 0; i < maxLen; i++) {
            int num1 = 0;
            int num2 = 0;
            if(i < v1.length){
                num1 = Integer.valueOf(v1[i]);
            }
            if (i < v2.length) {
                num2 = Integer.valueOf(v2[i]);
            }
            if (num1 > num2) return 1;
            if (num1 < num2) return -1;
        }
        return 0;
    }
}
